<?php
/**
 * 支付方式管理
 * @author cjli
 *
 */
class PaymentAction extends AdminAction
{
	public function _initialize()
	{
		parent::_initialize();
	}
	
	//支付方式列表
	public function payment_list()
	{
		$paymentList = PaymentModel::getPaymentList();
		$this->assign('paymentList', $paymentList);
		$this->display('payment_list');
	}

	//支付方式配置
	public function payment_edit()
	{
		$pname = trim($_GET['pname']);
		if(empty($pname)){
			$this->error('支付方式不存在！', U('payment/payment_list'));
		}
		if($_POST['dosubmit']){
			
			$lastId = PaymentModel::updatePaymentInfo($_POST);
			if($lastId){
				$this->success('支付方式配置成功！', U('payment/payment_list'));
			}else{
				$this->error('支付方式配置失败！', U('payment/payment_list'));
			}
		}else{
			import('COM.Payment');
			$paymentInstance = Payment::getInstance($pname);
			$paymentFields = $paymentInstance->getSettingFields();
			$this->assign('paymentFields', $paymentFields);
			$paymentInfo = PaymentModel::get_payment_info($pname);
			$paymentInfo['items'] = PaymentModel::getPaymentItems($pname);
			$paymentInfo['poundage_type'] = isset($paymentInfo['poundage_type']) ? $paymentInfo['poundage_type'] : 1;
			$paymentInfo['poundage_rate'] = $paymentInfo['poundage_type']==1 ? $paymentInfo['poundage'] : "10.00";
			$paymentInfo['poundage_fix'] = $paymentInfo['poundage_type']==2 ? $paymentInfo['poundage'] : '0';
			$this->assign('payment', $paymentInfo);
			$this->display('payment_edit');
		}
	}
	
	//删除支付方式
	public function payment_delete()
	{
		$pname = trim($_GET['pname']);
		if(empty($pname)){
			$this->error('支付方式不存在！', U('payment/payment_list'));
		}
		PaymentModel::deletePaymentInfo($pname);
		$this->success('支付方式删除成功！', U('payment/payment_list'));
	}
}